Object.defineProperty(exports, "__esModule", {
  value: true
});
var def_EventCenter = /* */function () {
  function _ctor() {
    babel_classCallCheck(this, _ctor);
  }
  return babel_createClass(_ctor, null, [{
    key: "hasEvent",
    value: function hasEvent(e) {
      return this.events.has(e);
    }
  }, {
    key: "regisEvent",
    value: function regisEvent(e, t, n) {
      if (null == e || null == t || null == n) {
        throw Error("regis event erro");
      }
      this.hasEvent(e) || _ctor.events.set(e, new Array());
      var s = new i(n, t, false);
      _ctor.events.get(e).push(s);
      this.checkWait(e);
    }
  }, {
    key: "regisEventOnce",
    value: function regisEventOnce(e, t, n) {
      if (null == e || null == t || null == n) {
        throw Error("regis event erro");
      }
      this.hasEvent(e) || _ctor.events.set(e, new Array());
      var s = new i(n, t, true);
      _ctor.events.get(e).push(s);
      this.checkWait(e);
    }
  }, {
    key: "checkWait",
    value: function checkWait(e) {
      var t = this.waitList.get(e);
      if (t && t.length > 0) {
        for (var _n5 = 0; _n5 < t.length;) {
          var _n6 = t.shift();
          this.postEvent(e, _n6);
        }
      }
    }
  }, {
    key: "postWaitEvent",
    value: function postWaitEvent(e, t) {
      if (this.pause || 1 == this.pausename[e]) {
        return;
      }
      var n = _ctor.events.get(e);
      if (null == n) {
        var _n7 = this.waitList.get(e);
        if (!_n7) {
          _n7 = [];
          this.waitList.set(e, _n7);
        }
        return void _n7.push(t);
      }
      for (var _o16 = 0; _o16 < n.length;) {
        var _e17 = n[_o16];
        if (null != _e17) {
          try {
            _e17.function.call(_e17.target, t);
            if (_e17.isOnce) {
              n.splice(_o16, 1);
              _o16--;
            }
          } catch (i) {
            console.log(i.message);
            console.log(i.stack.toString());
          }
        }
        _o16++;
      }
    }
  }, {
    key: "pauseAll",
    value: function pauseAll() {
      this.pause = true;
    }
  }, {
    key: "pauseEvent",
    value: function pauseEvent(e) {
      this.pausename[e] = 1;
    }
  }, {
    key: "resumeEvent",
    value: function resumeEvent(e) {
      this.pausename[e] = 0;
    }
  }, {
    key: "resumeAll",
    value: function resumeAll() {
      this.pause = false;
      this.pausename = {};
    }
  }, {
    key: "postEvent",
    value: function postEvent(e, t) {
      if (this.pause || 1 == this.pausename[e]) {
        return;
      }
      var n = _ctor.events.get(e);
      if (null != n) {
        for (var _o17 = 0; _o17 < n.length;) {
          var _e18 = n[_o17];
          if (null != _e18) {
            try {
              _e18.function.call(_e18.target, t);
              if (_e18.isOnce) {
                n.splice(_o17, 1);
                _o17--;
              }
            } catch (i) {
              console.log(i.message);
              console.log(i.stack.toString());
            }
          }
          _o17++;
        }
      }
    }
  }, {
    key: "removeEvent",
    value: function removeEvent(e, t, n) {
      var i = _ctor.events.get(e);
      if (null == i) {
        return;
      }
      var s = true;
      for (var _o18 = 0; _o18 < i.length; _o18++) {
        var a = i[_o18];
        if (undefined === a || a.target !== n || a.function !== t) {
          s = false;
        } else {
          i[_o18] = undefined;
          console.log("删除监听", e);
        }
      }
      s && _ctor.events.delete(e);
    }
  }, {
    key: "removeEventWithStarget",
    value: function removeEventWithStarget(e) {
      _ctor.events.forEach(function (t) {
        for (var _n8 = t.length - 1; _n8 >= 0; _n8--) {
          t[_n8].target.toString() == e.toString() && t.splice(_n8, 1);
        }
      });
    }
  }, {
    key: "removeEventWithEvevtName",
    value: function removeEventWithEvevtName(e) {
      _ctor.events.delete(e);
    }
  }, {
    key: "regiskeyCodeEvent",
    value: function regiskeyCodeEvent(e, t, n) {
      var a = 0;
      a |= 1 << n;
      for (var _o19 = 0; _o19 < (arguments.length <= 3 ? 0 : arguments.length - 3); _o19++) {
        a |= 1 << (_o19 + 3 < 3 || arguments.length <= _o19 + 3 ? undefined : arguments[_o19 + 3]);
      }
      if (_ctor.keyCodeEvents.has(a)) {
        throw Error("has keyCodeEvent ");
      }
      var r = new i(t, e, false);
      _ctor.keyCodeEvents.set(a, r);
      this._regiskeyCode();
    }
  }, {
    key: "removekeyCodeEvent",
    value: function removekeyCodeEvent(e) {
      var n = 0;
      n |= 1 << e;
      for (var _o20 = 0; _o20 < (arguments.length <= 1 ? 0 : arguments.length - 1); _o20++) {
        n |= 1 << (_o20 + 1 < 1 || arguments.length <= _o20 + 1 ? undefined : arguments[_o20 + 1]);
      }
      _ctor.keyCodeEvents.delete(n);
    }
  }, {
    key: "_regiskeyCode",
    value: function _regiskeyCode() {
      if (!this.regiskeyCodeok) {
        this.regiskeyCodeok = true;
        cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP, this._onKeyUp, this);
        cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this._onKeyDown, this);
      }
    }
  }, {
    key: "_onKeyUp",
    value: function _onKeyUp(e) {
      this.keyCodeoklist ^= 1 << e.keyCode;
    }
  }, {
    key: "_onKeyDown",
    value: function _onKeyDown(e) {
      var t = 1 << e.keyCode;
      if (0 == (this.keyCodeoklist & t) && (this.keyCodeoklist |= 1 << e.keyCode, _ctor.keyCodeEvents.has(this.keyCodeoklist))) {
        var _e19 = _ctor.keyCodeEvents.get(this.keyCodeoklist);
        if (null != _e19) {
          try {
            _e19.function.call(_e19.target, this.keyCodeoklist);
          } catch (n) {
            console.log(n.message);
            console.log(n.stack.toString());
          }
        }
      }
    }
  }]);
}();
exports.default = def_EventCenter;
def_EventCenter.events = new Map();
def_EventCenter.waitList = new Map();
def_EventCenter.pausename = {};
def_EventCenter.pause = false;
def_EventCenter.keyCodeEvents = new Map();
def_EventCenter.regiskeyCodeok = false;
def_EventCenter.keyCodeoklist = 0;
var i = /* */babel_createClass(function i(e, t) {
  var n = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  babel_classCallCheck(this, i);
  this.target = e;
  this.function = t;
  this.isOnce = n;
});